<?php
class TemplateAction extends BaseAction
{
    public function index()
    {
        $templates = D("Template")->select();
        $this->assign("templates", $templates);
        $this->assign("title", '模板设置');
        $this->display("Public:template");
    }

    public function add()
    {
        $this->display("Public:template");
    }

    public function doadd()
    {
        $data = $_POST;
        $Template = D("Template");
        $Template->Create();
        if ($Template->add($data)) {
            $this->success("添加成功！");
        } else {
            $this->error("添加失败！");
        }
    }

    public function edit()
    {
        if ($_GET['id']) {
            $templates = D("Template")->getById($_GET['id']);
            $this->assign($templates);
            $this->display("Public:template");
        } else {
            $this->assign("jumpUrl", "__URL__");
            $this->error("数据不存在！");
        }
    }

    public function doedit()
    {
        $data = $_POST;
        if (D("Template")->save($data)) {
            $this->success("修改成功！");
        } else {
            $this->error("修改失败！");
        }
    }

    public function batch()
    {
        $this->_batch();
    }

}
